﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FGHandler;
using System.Threading;
using System.Windows.Forms;

namespace FGHandler
{
    class Program
    {
        private FGHandler.LFSHandler _handler;
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new Form1());

        }

        public void Execute()
        {


            _handler = new LFSHandler();

            _handler.PlayerJoined += new LFSHandler.PlayerJoinedEventHandler(_handler_PlayerJoined);
            _handler.FGRaceTrackConnectionLeave += new LFSHandler.RaceTrackConnectionLeave(_handler_FGRaceTrackConnectionLeave);
            _handler.PlayerSplitTime += new LFSHandler.PlayerSplitTimeEventHandler(_handler_PlayerSplitTime);
            _handler.Connect();


            while (_handler.Connected)
            {
                Thread.Sleep(1);                
            }

            Console.WriteLine("Quit :(");
            Console.ReadLine();
        }

        void _handler_PlayerSplitTime(LFSHandler sender, lfsplayer player)
        {
            Console.WriteLine(player.PlayerName);
            foreach (FGHandler.Lap lap in player.LapList)
            {
                Console.WriteLine(lap.ToString());
            }
        }

        void _handler_FGRaceTrackConnectionLeave(LFSHandler sender, lfsplayer player)
        {            
            Console.WriteLine(player.PlayerName + " left :(");
        }

        void _handler_PlayerJoined(LFSHandler sender, lfsplayer player)
        {
            Console.WriteLine("{0}, {1}, {2}",player.PlayerName,player.PlayerID,player.ConnectionID);
        }
    }
}
